#include "lighting.h"

#include <cmath>
#include <algorithm>

namespace lighting
{
	float lambert(const vec3f N, const vec3f L)
	{
		float result = std::max(dot(N, L), 0.f);
		return result;
	}

	float phong(const vec3f N, const vec3f L, const pnt3f eye, const pnt3f point, const float power)
	{
		vec3f V = normalize(eye - point);
		vec3f R = reflect(L, N);

		float specular = static_cast<float>(std::pow(std::max(dot(R, V), 0.f), power));

		return specular;
	}

	float blinn(const vec3f N, const vec3f L, const pnt3f eye, const pnt3f point, const float power)
	{
		vec3f V = normalize(eye - point);
		vec3f H = normalize(L + V);

		float bl = static_cast<float>(std::pow(std::max(dot(N, H), 0.f), power));

		return bl;
	}
}